Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: collect har file on test fail #22526

Merged
merged 2 commits into from
Oct 2, 2023
Merged

feat: collect har file on test fail #22526

merged 2 commits into from
Oct 2, 2023

Conversation

dkwon17
Copy link
Contributor

@dkwon17 dkwon17 commented Sep 18, 2023

What does this PR do?

Fixes #22492

Uses https://www.npmjs.com/package/chrome-har to convert an array of network events into a har file. The har file is saved in the reports folder on test failures.

Screenshot/screencast of this PR

Viewing har file from tests/e2e/report/ within Chrome Developer Tools:

Screen.Recording.2023-09-25.at.11.47.17.AM.mov

What issues does this PR fix or reference?

#22492

How to test this PR?

  1. On an OpenShift cluster, install Eclipse Che
  2. Checkout this PR, cd to tests/e2e
  3. Run the following to set the necessary environment variables:
export TS_SELENIUM_BASE_URL=<CHE_URL>
export TS_SELENIUM_OCP_USERNAME=<USERNAME>
export TS_SELENIUM_OCP_PASSWORD=<PASSWORD>
export TS_SELENIUM_VALUE_OPENSHIFT_OAUTH=true
  1. Run npm ci
  2. Apply the following patch to guarantee that one of the smoke tests fail:
git apply <<EOF
diff --git a/tests/e2e/specs/SmokeTest.spec.ts b/tests/e2e/specs/SmokeTest.spec.ts
index 4a5f08bf76..709371a396 100644
--- a/tests/e2e/specs/SmokeTest.spec.ts
+++ b/tests/e2e/specs/SmokeTest.spec.ts
@@ -46,6 +46,7 @@ suite('The SmokeTest userstory', function (): void {
 		test('Check a project folder has been created', async function (): Promise<void> {
 			const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || StringUtil.getProjectNameFromGitUrl(factoryUrl);
 			projectSection = (await new SideBarView().getContent().getSections())[0]; // get the (WORKSPACE) section from the sidebar - contains project content
+			expect(false).to.be.true;
 			expect(await projectSection.findItem(projectName)).not.eqls(undefined);
 		});
 		test('Check the project files was imported', async function (): Promise<void> {
EOF
  1. Run the smoke tests
export USERSTORY=SmokeTest && npm run test
  1. The test should fail and a .har file should be available in tests/e2e/report/<test-name>/
  2. On Google Chrome / Firefox open Developer Tools and import the .har file under the network tab. The import should be successful, and you should see the list of network requests just like the demo above.

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@che-bot che-bot added target/branch Indicates that a PR will be merged into a branch other than master. status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. labels Sep 18, 2023
@@ -24,6 +24,7 @@ import { OAUTH_CONSTANTS } from '../constants/OAUTH_CONSTANTS';
import { REPORTER_CONSTANTS } from '../constants/REPORTER_CONSTANTS';
import { PLUGIN_TEST_CONSTANTS } from '../constants/PLUGIN_TEST_CONSTANTS';
import { inject, injectable } from 'inversify';
const chromeHar = require('chrome-har')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be performed using 'import' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using import causes an error:
image

There is no @types package for chrome-har, so I currently use the package like so:
https://github.com/eclipse/che/blob/88e2b95970fb07fb975dbd304c4124cf744380fa/tests/e2e/utils/CheReporter.ts#L29-L30

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, in this case I am ok with both solutions. We could create own "types" file but I don`t think it is necessary for just one dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I have left it at:

 // @ts-ignore: No module declaration file 
 import * as chromeHar from 'chrome-har'; 

@dkwon17 dkwon17 marked this pull request as ready for review September 25, 2023 17:41
@che-bot che-bot added the kind/task Internal things, technical debt, and to-do tasks to be performed. label Sep 25, 2023
@@ -21,6 +21,7 @@ export class ChromeDriver implements IDriver {

constructor() {
const options: Options = this.getDriverOptions();
options.setLoggingPrefs({performance: 'ALL'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like prettier script was not run before commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fixed in my latest commit

@dkwon17
Copy link
Contributor Author

dkwon17 commented Sep 29, 2023

I have fixed the conflict & rebased

@nallikaea nallikaea merged commit be6d9b8 into eclipse-che:main Oct 2, 2023
3 checks passed
@che-bot che-bot removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Oct 2, 2023
@nallikaea
Copy link
Contributor

@dkwon17 somehow you commited changes without linting check

12:04:17.015: [che] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false update-index --cacheinfo 100644,61fa55cab6add1b1cbc939c358501842031ffe63,tests/e2e/specs/dashboard-samples/Documentation.spec.ts --
12:04:17.043: [che] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F /tmp/git-commit-msg-.txt --amend --signoff --
> @eclipse-che/[email protected] lint
> eslint --fix .
/home/marynadolhalova/AquaProjects/che/tests/e2e/utils/CheReporter.ts
   29:1   error  Do not use "@ts-ignore" because it alters compilation errors  @typescript-eslint/ban-ts-comment
  181:10  error  Expected events to have a type annotation                     @typescript-eslint/typedef
  181:50  error  Missing return type on function                               @typescript-eslint/explicit-function-return-type
  182:10  error  Expected har to have a type annotation                        @typescript-eslint/typedef
✖ 4 problems (4 errors, 0 warnings)
husky - pre-commit hook exited with code 1 (error)

@dkwon17
Copy link
Contributor Author

dkwon17 commented Oct 5, 2023

I will be more careful next time, thank you for the fix: 0811b7e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/task Internal things, technical debt, and to-do tasks to be performed. target/branch Indicates that a PR will be merged into a branch other than master.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement an ability to store .har file in test report folder when execute Eclipse Che typescript UI test
3 participants